package edu.sctu.practice.class01.zhangwang.assigns.assign02;

import java.util.Scanner;

/**
 * Created by Z_W on 2015/9/24.
 */
public class Counter {
    private float sum = 0;
    private float reduces = 0;
    private float amasses = 0;
    private float dicision = 0;
    private float x = 0;
    private float y = 0;

    public Counter(float x,float y){
        this.x = x;
        this.y = y;
    }

    public float add(){
        sum = x+y;
        System.out.println();
        return sum;
    }

    public float reduce(){
        reduces = x-y;
        return reduces;
    }

    public float amass(){
        amasses = x*y;
        return amasses;
    }

    public float division(){
        if (y!=0){
            dicision = x/y;
        }else{
            System.out.println("被除数不能为0！");
        }
        return dicision;
    }

    public static void main(String[] args) {
        float x = 0;
        float y = 0;
        int type;

        System.out.println("请选择计算类型：1（加），2（减），3（乘），4（除）");

        System.out.println("请输入两个数：");
        Scanner scanner = new Scanner(System.in);
        type = scanner.nextInt();

        x = scanner.nextInt();
        y = scanner.nextInt();
        Counter counter = new Counter(x,y);
        switch (type){
            case 1:
                System.out.println("结果为："+counter.sum);
                break;
            case 2:
                System.out.println("结果为："+counter.reduces);
                break;
            case 3:
                System.out.println("结果为："+counter.amasses);
                break;
            case 4:
                System.out.println("结果为："+counter.dicision);
                break;
            default:
                System.out.println("选择错误！");
        }

    }
}
